﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace iTeamyou.LTS.Core.Migrations
{
    public partial class Update1008 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "RemainingDays",
                table: "SupplierLicenses");

            migrationBuilder.DropColumn(
                name: "RemainingDays",
                table: "ProductLicenses");

            migrationBuilder.DropColumn(
                name: "SupplierName",
                table: "ProductLicenses");

            migrationBuilder.DropColumn(
                name: "RemainingDays",
                table: "ManufacturerLicenses");

            migrationBuilder.RenameColumn(
                name: "ValidDate",
                table: "ManufacturerLicenses",
                newName: "ValidToDate");

            migrationBuilder.RenameColumn(
                name: "Tag",
                table: "ManufacturerLicenses",
                newName: "Type");

            migrationBuilder.AlterColumn<string>(
                name: "Register",
                table: "Manufacturers",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "RegisterCode",
                table: "Manufacturers",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "SupplierId",
                table: "Manufacturers",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "ManufacturerId",
                table: "ManufacturerLicenses",
                type: "varchar(95)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "LId",
                table: "ManufacturerLicenses",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "ValidFromDate",
                table: "ManufacturerLicenses",
                type: "datetime",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_ManufacturerLicenses_ManufacturerId",
                table: "ManufacturerLicenses",
                column: "ManufacturerId");

            migrationBuilder.AddForeignKey(
                name: "FK_ManufacturerLicenses_Manufacturers_ManufacturerId",
                table: "ManufacturerLicenses",
                column: "ManufacturerId",
                principalTable: "Manufacturers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ManufacturerLicenses_Manufacturers_ManufacturerId",
                table: "ManufacturerLicenses");

            migrationBuilder.DropIndex(
                name: "IX_ManufacturerLicenses_ManufacturerId",
                table: "ManufacturerLicenses");

            migrationBuilder.DropColumn(
                name: "RegisterCode",
                table: "Manufacturers");

            migrationBuilder.DropColumn(
                name: "SupplierId",
                table: "Manufacturers");

            migrationBuilder.DropColumn(
                name: "LId",
                table: "ManufacturerLicenses");

            migrationBuilder.DropColumn(
                name: "ValidFromDate",
                table: "ManufacturerLicenses");

            migrationBuilder.RenameColumn(
                name: "ValidToDate",
                table: "ManufacturerLicenses",
                newName: "ValidDate");

            migrationBuilder.RenameColumn(
                name: "Type",
                table: "ManufacturerLicenses",
                newName: "Tag");

            migrationBuilder.AddColumn<int>(
                name: "RemainingDays",
                table: "SupplierLicenses",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "RemainingDays",
                table: "ProductLicenses",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "SupplierName",
                table: "ProductLicenses",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.UpdateData(
                table: "Manufacturers",
                keyColumn: "Register",
                keyValue: null,
                column: "Register",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "Register",
                table: "Manufacturers",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "ManufacturerId",
                table: "ManufacturerLicenses",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "varchar(95)")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<int>(
                name: "RemainingDays",
                table: "ManufacturerLicenses",
                type: "int",
                nullable: true);
        }
    }
}
